//
//  OSCTabBarController.swift
//  OSCChina
//
//  Created by 刘威 on 2016/11/30.
//  Copyright © 2016年 刘威. All rights reserved.
//

import UIKit

class OSCTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        initTabBar()
    }

    func initTabBar(){
        addChildViewController(NewsViewController(), title: "首页", imageName: "tabbar")
        addChildViewController(UIViewController(), title: "其他", imageName: "")
        addChildViewController(UIViewController(), title: "测试", imageName: "")
        addChildViewController(UIViewController(), title: "我的", imageName: "")
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    private func addChildViewController(_ childController: UIViewController,title : String,imageName:String) {
        
        //1:设置子控制器tabBarItem的标题图片
        childController.title = title;
        childController.tabBarItem.image = UIImage(named: imageName)
        childController.tabBarItem.selectedImage = UIImage(named: imageName + "_highlighted")
        
        //2:添加子控制器
        let childNav = OSCNavigationController(rootViewController: childController)
        childNav.navigationBar.barTintColor = UIColor(red: 36/255.0, green: 207/255.0, blue: 95/255.0, alpha: 1.0)
        let navigationTitleAttribute = NSDictionary(object: UIColor.white, forKey: NSForegroundColorAttributeName as NSCopying)
        childNav.navigationBar.titleTextAttributes = navigationTitleAttribute as! [String : AnyObject]
        addChildViewController(childNav)
        
    }

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
